package com.lz.football.module.club
{
	import com.common.utils.DisplayObjectUtil;
	import com.common.utils.Reflection;
	import com.lz.football.module.base.IComponent;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.ProgressEvent;
	import flash.net.URLRequest;
	import flash.system.LoaderContext;

	/**
	 * 球衣+人 
	 * @author Administrator
	 * 
	 */	
	public class ClothManContain extends Sprite implements IComponent
	{
		/**
		 *球服ID 
		 */
		public var _id:int;
		public  var _loader:Loader;
		
		public function ClothManContain()
		{
			super();
			initUI();
		}
		
		public function initUI(view:Object=null):void
		{
			_loader = new Loader();
			this.mouseChildren = false;
			this.mouseEnabled = false;
			
		}
		public function urlById($id:int):void
		{
			if($id == _id)return;
			DisplayObjectUtil.removeAllChildren(this);
			_id = $id;
			for(var i:int = 0;i < 10;i++)
			{
				var bitmapdata:BitmapData =  Reflection.createInstance("ui.lz.cloth_"+$id);
				var bit:Bitmap = new Bitmap(bitmapdata);
				this.addChild(bit)
				bit.x = i * 20 - 40;
				bit.y = -10;
			}
			
			
			
			
			
			
			return;
			
			
			
			clear();
			
			load();
		}
		public function load():void
		{
			var request:URLRequest = new URLRequest("res/swf/cloths/"+_id+".swf");
			var content:LoaderContext = new LoaderContext(true,null,null);
			
			
			_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHandler);
			_loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
			_loader.contentLoaderInfo.addEventListener(Event.OPEN,openHandler);
			_loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
			_loader.load(request,content);

		}
		public function progressHandler(event:ProgressEvent):void
		{
//			trace("progressHandler: bytesLoaded=" + event.bytesLoaded + " bytesTotal=" + event.bytesTotal);

		}
		public function ioErrorHandler(event:IOErrorEvent):void
		{
//			trace("加载错误");
		}
		public function completeHandler(e:Event):void
		{
			removeEvtListener();
			var resoure:MovieClip = Reflection.createInstance("com.footbal.cloth_"+_id,e.target.applicationDomain);
			this.addChild(resoure);
		}
		private function clear():void
		{
			DisplayObjectUtil.removeAllChildren(this);
			unload();
		}
		private function unload():void
		{
			try
			{
				_loader.close();
			}
			catch(e:Error)
			{
				
			}
			_loader.unloadAndStop();
			removeEvtListener();
		}
		/**
		 * 
		 * @param event
		 * 
		 */
		private function openHandler(event:Event):void
		{
			
		}
		public function addEvtListener():void
		{
		}
		
		public function removeEvtListener():void
		{
			_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,completeHandler);
			_loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
			_loader.contentLoaderInfo.removeEventListener(Event.OPEN,openHandler);
		}
		
		public function destroyView():void
		{
			clear();
			_loader = null;
		}
	}
}